﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Application
open System.Security;

// =======================================================
// Apply validation formulas and messages to fields
// =======================================================

let ProvisioningList = Client.Context.Web.Lists.GetByTitle("Provisioning")
let Title = ProvisioningList.Fields.GetByInternalNameOrTitle("Title")
Client.Context.Load(Title)
Client.Context.ExecuteQuery()

Title.ValidationFormula <- @"=AND(LEN(Title)<=29,
    ISERR(FIND(""."",[Title])),
    ISERR(FIND(""!"",[Title])),
    ISERR(FIND(""§"",[Title])),
    ISERR(FIND(""$"",[Title])),
    ISERR(FIND(""%"",[Title])),
    ISERR(FIND(""&"",[Title])),
    ISERR(FIND(""("",[Title])),
    ISERR(FIND("")"",[Title])),
    ISERR(FIND(""="",[Title])),
    ISERR(FIND(""?"",[Title])),
    ISERR(FIND(""["",[Title])),
    ISERR(FIND(""]"",[Title])),
    ISERR(FIND(""<"",[Title])),
    ISERR(FIND("">"",[Title])),
    ISERR(FIND(""@"",[Title])),
    ISERR(FIND(""|"",[Title])),
    ISERR(FIND(""^"",[Title])),
    ISERR(FIND(""°"",[Title])),
    ISERR(FIND(""´"",[Title])),
    ISERR(FIND(""`"",[Title])),
    ISERR(FIND(""#"",[Title])),
    ISERR(FIND(""'"",[Title])),
    ISERR(FIND(""+"",[Title])),
    ISERR(FIND(""*"",[Title])),
    ISERR(FIND("","",[Title])),
    ISERR(FIND("";"",[Title])),
    ISERR(FIND(""²"",[Title])),
    ISERR(FIND(""³"",[Title]))
    )";
Title.ValidationMessage <- "The title can only contain up to 29 characters. Special characters are not allowed."
Title.Update()
Client.Context.ExecuteQuery()